package com.task.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.task.bean.Student;
import com.task.bean.Teacher;
import com.task.mapper.TeacherMapper;
import com.task.service.ITeacherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liuzhe
 * @since 2021-04-10
 */
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements ITeacherService {

    @Override
    public Teacher getByUsernameAndPassword(Teacher teacher) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("username", teacher.getUsername());
        queryWrapper.eq("password", teacher.getPassword());
        List<Teacher> list = baseMapper.selectList(queryWrapper);
        return list.get(0);
    }

    @Override
    public List<Teacher> queryTeaPage(int pageNum, int pageSize) {
        IPage<Teacher> teacherIPage = new Page<>(pageNum, pageSize);
        IPage page = baseMapper.selectPage(teacherIPage, null);
        return page.getRecords();
    }
}
